<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <form onsubmit="return false">
        <p><label for="">用户名：<input type="text" name="user" class="user"></label></p>
        <p><label for="">密&nbsp;&nbsp;码：<input type="text" name="pwd" class="pwd"></label></p>
        <button class="btn">提交</button>
    </form>
    <script>
        var user = document.querySelector(".user");
        var pwd = document.querySelector(".pwd");
        var btn = document.querySelector(".btn");
        // console.log(pwd);
        btn.onclick = function () {
            var userval = user.value;
            var pwdval = pwd.value;
            // console.log(user.value);
            if (userval && pwdval) {
                var xhr = new XMLHttpRequest();
                xhr.open("get", "../4.get.php?user=" + userval + "&pwd=" + pwdval, true);
                xhr.send();
                xhr.onreadystatechange = function () {
                    if (xhr.readyState == 4 && xhr.status == 200) {
                        console.log(xhr.responseText);
                        var str = JSON.parse(xhr.responseText);
                        console.log(str);
                    }
                }

            }
        }

    </script>
</body>

</html>